package com.yoomiito.app.ui.my.psw;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yoomiito.app.R;
import com.yoomiito.app.base.App;
import com.yoomiito.app.base.BaseLazyFragment;
import com.yoomiito.app.utils.AllUtils;
import com.yoomiito.app.utils.SoftKeyBoardUtils;
import com.yoomiito.app.utils.UserInfoConfig;
import com.yoomiito.app.widget.DownTimeButton;
import com.yoomiito.app.widget.PasswordView_1;

import butterknife.BindView;
import butterknife.OnClick;

public class VerifyCodeFragment extends BaseLazyFragment<VerifyCodePresenter> {

    @BindView(R.id.fm_verify_code_show_tel)
    TextView mTel;
    @BindView(R.id.fm_verify_code_down_time)
    DownTimeButton mTimeButton;
    @BindView(R.id.psw)
    PasswordView_1 mPasswordView;
    @BindView(R.id.parent_view)
    LinearLayout parentView;
    @Override
    public int getLayoutId() {
        return R.layout.fm_verify_code;
    }

    @Override
    public VerifyCodePresenter newP() {
        return new VerifyCodePresenter(App.mAppConfig);
    }

    @Override
    public void initData(Bundle savedInstanceState) {

        SoftKeyBoardUtils.showView(parentView,mPasswordView);

        mTel.setText("验证码发送至"+ UserInfoConfig.getTel());
        mPasswordView.setTypeface();
        mPasswordView.setTextSize(45);
        mPasswordView.setTextChangedListener(new PasswordView_1.TextChangedListener() {
            @Override
            public void textChanged(CharSequence changeText) {

            }

            @Override
            public void textCompleted(CharSequence text) {
                showLoading();
                getP().verifySms(text.toString());
            }
        });
    }

    @OnClick({R.id.fm_verify_code_down_time})
    public void onClick(View view){
        if (R.id.fm_verify_code_down_time==view.getId()){
            if (AllUtils.isFastClick()){
                return;
            }
            showLoading();
            getP().sendSms();
        }
    }

    public void sendSms(){
        dismissLoading();
        mTimeButton.downTime();
    }

    public void verifySmsCode(){
        dismissLoading();
        ((SetPayPswActivity)context).switchFm(1);
    }

    @Override
    protected void onDestroyLazy() {
        if (mTimeButton!=null)
            mTimeButton.dispose();
//        SoftKeyBoardUtils.removeListener();
        super.onDestroyLazy();

    }
}
